class Session < ActiveRecord::Base

  def self.create_token( user_id )
    offset = (?a).to_i
    time = DateTime.now.strftime("%m%d%y%I%M%S").to_i

    pre = ""
    user_id.to_s.each_char { |c| pre += (c.to_i + offset).chr }

    post = ""
    time.to_s.each_char { |c| post += (c.to_i + offset).chr }

    post = post.to_s
    limit = post.size.to_i
    
    0.upto(limit.to_i) { |n|
      post[n] = post[n].chr + time.to_s[n].chr.to_s if (n % 2 == 0)
    }

    token = pre.to_s + user_id.to_s + "-" + post.to_s

    return token
  end

end
